#ifndef COMPARE_H
#define	COMPARE_H

#include "list.h"
#include "utils.h"

template<typename Num1, typename Num2>
struct Compare_
{
   static const int result = IntIf<Num1::data != Num2::data,
           Num1::data - Num2::data, Compare_<typename Num1::tail, typename Num2::tail>::result >::result;
};

template<typename Num1>
struct Compare_<Num1, EmptyList>
{
   static const int result = 0;
};

template<typename Num2>
struct Compare_<EmptyList, Num2>
{
   static const int result = 0;
};

template<>
struct Compare_<EmptyList, EmptyList>
{
   static const int result = 0;
};

template<int x>
struct Abs
{
   static const int result = IntIf<(x > 0), x, -x>::result;
};

template<typename Num1, typename Num2>
struct Compare
{
   static const int result = IntIf<Length<Num1>::length != Length<Num2>::length,
           IntIf<((Length<Num1>::length - Length<Num2>::length) > (0)),
           Compare_<Num1, typename Shift<Num2,
           Abs<Length<Num1>::length - Length<Num2>::length>::result>::result
           >::result,
           Compare_<typename Shift<Num1,
           Abs<Length<Num2>::length - Length<Num1>::length >::result >::result,
           Num2 >::result >::result,
           Compare_<Num1, Num2>::result >::result;
};

#endif

